import com.day1Am.Utils.GetMybatisSessionUtils;
import com.day1Am.mapper.UserMapper;
import com.day1Am.pojo.User;
import org.apache.ibatis.session.SqlSession;
import org.junit.Test;

import java.util.List;

/**
 * @author cc
 * @date 2021/8/4 11:49
 * @Description
 */

public class test {
    SqlSession getsession = GetMybatisSessionUtils.getsession();
    UserMapper userMapper = getsession.getMapper(UserMapper.class);
    /**
     * 第一种复杂写法
     * @author sosmcc
     * @param
     */

//   UserMapper userMapper = new UserMapperImpl();
//   @Test
//   public void test (){
//       List<User> users = userMapper.findallUser();
//       for (User user : users) {
//           System.out.println(user);
//       }
//   }

    /**
     * 第二种，通过jdk的动态代理来把接口转换成实现类 
     * @author sosmcc
     * @param
     */
    @Test
    public void findAllUser(){
        List<User> users = userMapper.findallUser();
        for (User user : users) {
            System.out.println(user);
        }
    }
    @Test
    public void addUser(){
        int i = userMapper.addUser(new User("999", "test999", "testpassword"));
        System.out.println(i<1?"添加失败":"添加成功");
    }
    @Test
    public void delect(){
        String id = "999";
        int delect = userMapper.delect(id);
        System.out.println(delect<1?"删除失败":"删除成功");

    }
    @Test
    public void update(){
//        String id = "999";
        User updateuser = new User("999", "test998", "testpass");
        int update = userMapper.update(updateuser);
        System.out.println(update<1?"更新失败":"更新成功");

    }
}
